<#include "layout.html"/>
<@layout>
<h2 class="sub-header">
类别列表
<button class="btn btn-default pull-right" data-toggle="modal" data-target="#addModal">新增&nbsp;<span class="glyphicon glyphicon-plus"></button>
</h2>
<div class="table-responsive">
  <table class="table table-striped">
    <thead>
      <tr>
        <th>序号</th>
        <th>名称</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody>
    	<#list page.list as project>
    	<tr>
	        <td>${project.id}</td>
	        <td>${project.name}</td>
	        <td>
	        	<a class="btn btn-danger" href="${path}/admin/project/delete/${project.id}.html" role="button"><span class="glyphicon glyphicon-trash"></span>删除</a>
	        </td>
	    </tr>
		</#list>
    </tbody>
  </table>
</div>	
 <div class="pull-right">
 	<@pagination prefix="&q=${q!}" pageNum=page.pageNumber totalPage=page.totalPage/>
 </div>
 
<!-- 模态框（Modal） -->
<div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" 
               data-dismiss="modal" aria-hidden="true">
                  &times;
            </button>
            <h5 class="modal-title" id="myModalLabel">
            	新增
            </h5>
         </div>
         <div class="modal-body">
         	<input type="text" class="form-control" placeholder="类别名称" id="proName" value="">
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭
            </button>
            <button type="button" class="btn btn-primary" onclick="projectSubmit()" id="submitBtn">
            	提交
            </button>
         </div>
      </div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>

<div class="modal fade" id="msgModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
         <div class="alert alert-dismissable" id="alertMsg">
         	<button type="button" class="close" 
               data-dismiss="modal" aria-hidden="true">
                  &times;
            </button>
		   <span id="msg"></span>
         </div>
	</div><!-- /.modal -->
</div>
<script type="text/javascript">
$('#msgModal').on('hide.bs.modal', function () {location.href="${path}/admin/project/";})

function projectSubmit(){
	if($('#proName').val().trim() == ""){
		return;
	}
	$.post("${path}/admin/project/addProject",{'project.name':$('#proName').val()},function(data){
		$('#proName').val("");
		$('#addModal').modal('hide');
		$('#msg').html(data.msg);
		if(data.success == true){
			$('#alertMsg').removeClass("alert-danger");
			$('#alertMsg').addClass("alert-success");
		}else{
			$('#alertMsg').removeClass("alert-success");
			$('#alertMsg').addClass("alert-danger");
		}
		$('#msgModal').modal('show');
	},"json");
}
</script>	
</@layout>
